<<<<<<< HEAD
import sys
import numpy
import re
import matplotlib.pyplot as plt

scinot = re.compile('[+\-]?(0|[1-9]\d*)(\.\d*)([eE][+\-]?\d+)?')


def conv(bs):
    s = bs.decode("ascii")
#    print(s)
    p = re.search(scinot, s)
    r = s[0:p.span()[1]]
    img = s[p.span()[1]:-1]
    c = complex(float(r), float(img))
#    print(c)
    return c



# compare result of python program and that of matlab
# example:read in npy created by stft.py  and compare against the result by matlab

if len(sys.argv)<3:
    print('usage:')
    sys.exit(0)

npy = sys.argv[1]

# 98*50
txt = sys.argv[2]
py = numpy.load(npy)
print(py.shape)

matlab = numpy.loadtxt(txt, converters=conv,dtype=complex)
print(matlab.shape)

#print(numpy.isnan(py))
#print(numpy.isnan(matlab))
diff= numpy.abs(py-matlab)
sqr = diff **2
print(sqr.shape)
tmp = sqr.reshape(1,-1)
sum = numpy.sum( tmp)
max = numpy.max( tmp)
#print(sqr)


plt.figure(0)
x = sqr.shape[0]
y = sqr.shape[1]
Y = numpy.arange(0, y / 100, 0.01)
X = numpy.arange(0, x / 100, 0.01)
c = plt.pcolormesh(Y,X,sqr, shading='nearest')
plt.colorbar(c)

freq=numpy.arange(x)
plt.figure(1)
plt.plot(freq,py)
plt.figure(2)
plt.plot(freq,matlab)
plt.show()
print("sum:%f"%sum)
=======
import sys
import numpy
import re
import matplotlib.pyplot as plt

scinot = re.compile('[+\-]?(0|[1-9]\d*)(\.\d*)([eE][+\-]?\d+)?')


def conv(bs):
    s = bs.decode("ascii")
#    print(s)
    p = re.search(scinot, s)
    r = s[0:p.span()[1]]
    img = s[p.span()[1]:-1]
    c = complex(float(r), float(img))
#    print(c)
    return c



# compare result of python program and that of matlab
# example:read in npy created by stft.py  and compare against the result by matlab

if len(sys.argv)<3:
    print('usage:')
    sys.exit(0)

npy = sys.argv[1]

# 98*50
txt = sys.argv[2]
py = numpy.load(npy)
print(py.shape)

matlab = numpy.loadtxt(txt, converters=conv,dtype=complex)
print(matlab.shape)

#print(numpy.isnan(py))
#print(numpy.isnan(matlab))
diff= numpy.abs(py-matlab)
sqr = diff **2
print(sqr.shape)
tmp = sqr.reshape(1,-1)
sum = numpy.sum( tmp)
max = numpy.max( tmp)
#print(sqr)


plt.figure(0)
x = sqr.shape[0]
y = sqr.shape[1]
Y = numpy.arange(0, y / 100, 0.01)
X = numpy.arange(0, x / 100, 0.01)
c = plt.pcolormesh(Y,X,sqr, shading='nearest')
plt.colorbar(c)

freq=numpy.arange(x)
plt.figure(1)
plt.plot(freq,py)
plt.figure(2)
plt.plot(freq,matlab)
plt.show()
print("sum:%f"%sum)
>>>>>>> 4eba858 (bug fix and add test scripts)
print("max:%f"%max)